package com.cao.meet.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.LogUtils;
import com.cao.meet.R;
import com.cao.meet.mvp.contract.LoginContract;
import com.cao.meet.mvp.presenter.LoginPresenter;

public class LoginActivity extends AppCompatActivity implements LoginContract.View {

    private EditText user_name;
    private EditText pass_word;
    private Button please_login;
    private LoginContract.Presenter login_presenter;
    private Button get_result;
    private TextView login_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        user_name = (EditText) findViewById(R.id.user_name);
        pass_word = (EditText) findViewById(R.id.pass_words);
        please_login = (Button) findViewById(R.id.please_login);
        get_result = (Button) findViewById(R.id.get_result);
        login_text = (TextView) findViewById(R.id.login_text);
        initDatas();
    }

    private void initDatas() {
        please_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userName = user_name.getText().toString();
                String passWord = pass_word.getText().toString();
                login_presenter = new LoginPresenter();
                login_presenter.login(LoginActivity.this,userName,passWord);
            }
        });
        get_result.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                login_presenter.getResult(null, new LoginPresenter.ResultInter() {
                    @Override
                    public void terurn_json(String json) {
                        LogUtils.e("json",json);
                        login_text.setText(json);
                    }
                });
            }
        });
    }

    @Override
    public void showToast(String json) {
        Toast.makeText(this, "登陆成功", Toast.LENGTH_SHORT).show();
        login_presenter.getResult(json, new LoginPresenter.ResultInter() {
            @Override
            public void terurn_json(String json) {
                LogUtils.e("json",json);
            }
        });
    }
}
